﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace Eneta.Portal.Forum
{
    public class MasterBaseWithDesignHack : MasterPage
    {
        protected HtmlControl _hackContainer;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (Request.QueryString["control"] == "ViewMessages" ||
                Request.QueryString["control"] == "UpdateMessage")
                if (_hackContainer != null)
                    _hackContainer.Attributes["class"] = "thread";
        }

        public void SetRssLinks(RssLinksDto dto)
        {
            if (dto == null)
            {
                return;
            }
            if(dto.RssVisible)
            {
                var rssLink = FindControl("rssLinkUpper") as HtmlAnchor;
                if(rssLink != null)
                {
                    if (!string.IsNullOrEmpty(dto.RssUrl))
                    {
                        rssLink.HRef = dto.RssUrl;
                        rssLink.InnerText = dto.RssTitle;
                    }
                    else
                        rssLink.Visible = false;
                }
                
                rssLink = FindControl("rssLinkBottom") as HtmlAnchor;
                if (rssLink != null)
                {
                    if (!string.IsNullOrEmpty(dto.RssUrl))
                    {
                        rssLink.HRef = dto.RssUrl;
                        rssLink.InnerText = dto.RssTitle;
                    }
                    else
                        rssLink.Visible = false;
                }
            }

            var container = FindControl("rssLinkContainer");
            if (container != null)
                container.Visible = dto.RssVisible;
            container = FindControl("rssLinkBottomContainer");
            if (container != null)
                container.Visible = dto.RssVisible;

            if(dto.CommentsRssVisible)
            {
                var rssLink = FindControl("rssCommentsLinkUpper") as HtmlAnchor;
                if (rssLink != null)
                {
                    rssLink.HRef = dto.CommentsRssUrl;
                    rssLink.InnerText = dto.CommentsRssTitle;
                }

                rssLink = FindControl("rssCommentsLinkBottom") as HtmlAnchor;
                if (rssLink != null)
                {
                    rssLink.HRef = dto.CommentsRssUrl;
                    rssLink.InnerText = dto.CommentsRssTitle;
                }
            }
            container = FindControl("rssCommentsLinkContainer");
            if (container != null)
                container.Visible = dto.CommentsRssVisible;
            container = FindControl("rssCommentsLinkBottomContainer");
            if (container != null)
                container.Visible = dto.CommentsRssVisible;
        }
    }
}
